package com.example.demo01.Socket.Codec.decode;

import cn.hutool.core.util.StrUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;
import java.util.List;


@Slf4j
public class MyMessageDecoder2 extends ByteToMessageDecoder {




    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {




        log.info("MyMessageDecoder2 length:"+byteBuf.readableBytes());

        if(byteBuf.readableBytes()>=2){

            log.info("MyMessageDecoder2 byteBuf.readableBytes()> "+byteBuf.readableBytes());

            short len= byteBuf.readShort();

            log.info("MyMessageDecoder2 header length:"+len);

            ByteBuf header=byteBuf.readBytes(4);

            log.info(StrUtil.str(header.array(), StandardCharsets.UTF_8));

           // list.add(byteBuf);

//            PacketInstruction packet=new PacketInstruction();
//            packet.setTelNo("01");




        }




    }
}
